<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        {{ date }}
    </div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data:{
                    date: new Date()
            },
            mounted: function(){ // 这里为什么使用箭头函数不行呢？深入了解
                var _this = this;
                this.timer = setInterval(()=>{
                    _this.date = new Date(); //修改数据date
                }, 1000);
            },
            beforeDestroy: ()=>{
                if(this.timer){
                    clearInterval(this.timer);
                }
            }
        })
    </script>
</body>
</html>